package com.example.xuecheng.contentservice.controller;

import com.example.xuecheng.contentservice.service.impl.CourseBaseInfoServiceImpl;
import dto.*;
import exception.ValidationGroups;
import exception.XueChengException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import model.PageParams;
import model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import po.CourseBase;

/**
 * @author xiehaidong
 */
@RestController
@RequestMapping("/course")
@Api(description = "课程信息管理接口")
public class CourseBaseInfoController {
    @Autowired
    private CourseBaseInfoServiceImpl courseBaseInfoService;
    @PostMapping("/list")
    @ApiOperation("课程查询接口")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required = false) QueryCourseParamsDto queryCourseParamsDto){
        return  courseBaseInfoService.queryCourseBaseList(pageParams,queryCourseParamsDto);
    }
    @PostMapping("")
    @ApiOperation("新增课程基本信息")
    public void addCourseBaseInfo(@RequestBody@Validated({ValidationGroups.insert.class}) AddCourseBaseDto addCourseBaseDto){
        Long companyId = 1232141425L;
       courseBaseInfoService.addCourseBaseInfo(companyId,addCourseBaseDto);

    }
    @PutMapping("")
    @ApiOperation("编辑课程信息接口")
    public void editCourseBaseInfo(@RequestBody@Validated({ValidationGroups.update.class}) EditCourseBaseDto editCourseBaseDto){
        Long companyId = 1232141425L;
         courseBaseInfoService.editCourseBaseInfo(companyId,editCourseBaseDto);

    }

    @GetMapping("/{courseId}")
    @ApiOperation("查询详细课程信息")
    public CourseBaseInfoDto getCourseBaseInfoDtoById(@PathVariable(value = "courseId") Long courseId){
        return courseBaseInfoService.getCourseBaseInfoDto(courseId);
    }
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除课程")
    public void deleteCourse(@PathVariable(value = "courseId") Long courseId){
        Long companyId = 1232141425L;
        courseBaseInfoService.deleteCourse(companyId,courseId);
    }

    @GetMapping("/test")
    @ApiOperation("测试")
    public void test(){
        throw new XueChengException(400,"异常测试");
    }


}
